home *** CD-ROM | disk | FTP | other *** search
- Path: uuneo.neosoft.com!usenet
- From: Wmatthew@lan-aces.com (W. Matthews)
- Newsgroups: comp.lang.c++
- Subject: Re: Virtual Base Class
- Date: 11 Mar 1996 15:26:55 GMT
- Organization: LAN-ACES, Inc.
- Message-ID: <4i1gnv$b7i@uuneo.neosoft.com>
- References: <313F98D0.102E@ucla.edu>
- NNTP-Posting-Host: 198.65.178.8
- X-Newsreader: WinVN 0.92.5
-
- In article <313F98D0.102E@ucla.edu>, Dennis Rahaman <dennisr@ucla.edu> says:
- >
- >This is what I want to do:
- >
- > a
- > / \
- > b c
- > \ /
- > d
- >
- >
- >class a
- > {
- > //...
- > };
- >
- >class b : public virtual a
- > {
- > //...
- > };
- >
- >class c : public virtual b
- > {
- > //...
- > };
- >
- >class d : public b, public c
- > {
- > //...
- > };
- >
- >
- >void f ()
- > {
- > a a1;
- > d* pd = (d*) &a1; // error: can't cast virtual base to derived
- > }
- >
- >///////////////////////////////////////////////////////////
- >Can someone explain why I can't cast a virtual base class to a derived
- >class?
- >
- >What should I do instead?
- >
- >Any help would be appreciated.
- >
- >- Dennis
- I would surmise that this is due to the fact that the virtual base does not
- have the entire memory picture of the derived class. Anything declared in
- the derived class would not always have a counter part in that virtaul base.
- ______________________________________________
- |Wyatt Matthews: Tech Support Department |
- |WMATTHEW@LAN-ACES.COM -Internet- |
- |WMATTHEW.MHS@LAN-ACES -MHS- |
- |LAN-ACES Tech Support (713)890-9786 |
- |LAN-ACES BBS (713)890-9790 |
- |LAN-ACES Fax (713)890-9731 |
- |LAN-ACES Sales (713)890-9787 |
- ______________________________________________
-